{include file="public/nheader"}
<div class="layui-fluid layui-bg-white">
    <form action="{:url()}" class="layui-form layui-form-fixed">
        <div class="layui-form-item">
            <label class="layui-form-label">
                <font color="red">* </font>师傅
            </label>
            <div class="layui-input-block">
                <select name="riderid">
                    <option value="">请选择师傅账号</option>
                    {foreach $rider as $v}
                    <option value="{$v.id}" {if !empty($row.riderid) && $row.riderid==$v.id}selected{/if}>
                        {$v.name}（{$v.mobile}）</option>
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <font color="red">* </font>省份
            </label>
            <div class="layui-input-block">
                <select name="province" data-area="" lay-filter="province">
                    <option value="">请选择选择省份</option>
                    {foreach $province as $v}
                    <option value="{$v.area_code}" {if !empty($row.province) &&
                        $row.province==$v.area_code}selected{/if}>{$v.name}</option>
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <font color="red">* </font>城市
            </label>
            <div class="layui-input-block">
                <select name="city" data-area="" lay-filter="city">
                    <option value="">请选择选择城市</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <font color="red">* </font>区域
            </label>
            <div class="layui-input-block">
                <select name="area" data-area="" lay-filter="area">
                    <option value="">请选择选择区域</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item" id="streetshow">
            <label class="layui-form-label">
                <font color="red">* </font>街道
            </label>
            <div class="layui-input-block">
                <select name="street" data-area="" lay-filter="street">
                    <option value="">请选择选择街道</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                一键选择
            </label>
            <div class="layui-input-block">
                <input type="checkbox" lay-skin="switch" lay-text="全选|取消" lay-filter="father">
            </div>
        </div>
        <div class="layui-form-item">
            <font color="red">1、如街道无权限或无代理将跳过该街道添加</font>
        </div>
        <div class="layui-footer layui-form-item layui-center ">
            <button class="layui-btn" lay-filter="submitIframe" type="button" lay-submit>提交</button>
            <button class="layui-btn layui-btn-primary" type="button" sa-event="closeDialog">取消</button>
        </div>
    </form>
</div>

{include file="public/nfooter"}
<script>
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer;
            
        form.on('switch(father)', function (data) {
            var leng = $("input[type='checkbox']").length;
            if (data.elem.checked) {
                if (leng <= 1) {
                    layer.msg('暂无可选中项,请填写相关信息后再重试', { icon: 2, time: 1000 });
                    return false;
                }
                $('input[type="checkbox"]').prop("checked", true);
                form.render();
            } else {
                $('input[type="checkbox"]').prop("checked", false);
                form.render();
            }
        });
        //监听区域选择
        form.on('select(area)', function (data) {
            //发异步，把数据提交给php
            $.ajax({
                type: 'get',
                url: '/base/getregion',
                data: { area_code: data.value, level: 4 },
                success: function (res) {
                    if (res.code == 200) {
                        var str = '';
                        $.each(res.data, function (i, obj) {
                            str += '<input name="street[]" type="checkbox" lay-skin="primary" value="' + obj.id + '" title="' + obj.name + '" />';
                        });
                        $('#streetshow .layui-input-block').html(str);
                        form.render();
                    } else {
                        layer.msg(res.msg, { icon: 2, time: 1000 });
                    }
                }
            });
            return false;
        });

    });
</script>